<template>
  <div>
    <el-button type="primary" @click="rowNew">新增</el-button>
    <el-button type="success" >导出</el-button>
    <el-button type="success" >审核</el-button>
    <el-button type="danger" >审核不通过</el-button>
    <el-button type="warning" >取消审核</el-button>
    <el-button type="primary" >转发</el-button>
    <el-button type="success" >处理</el-button>
    <!--表格内容-->
    <el-table
      ref="list"
      :data="tableData"
      style="width: 100%;margin-top: 1vw"
      border
      stripe
      highlight-current-row
      :default-sort="{prop: 'date', order: 'descending'}"
      @row-click="handleRowClick"
      @select-all="handleCheckedAllAndCheckedNone"
      @select="handleCheckedAllAndCheckedNone">
      <el-table-column property="col11" label="器械实际使用场所" width="150" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column property="col14" label="事件陈述" width="200" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column property="col10" label="器械故障" width="120" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column property="col35" label="报告日期" width="150" sortable :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <i class="el-icon-time"></i>
          <span style="margin-left: 5px">{{scope.row.col35}}</span>
        </template>
      </el-table-column>
      <el-table-column property="col37" label="报告人姓名" width="120"></el-table-column>
      <el-table-column property="col1" label="患者姓名" width="120" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column property="name" label="器械类型" width="120" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column property="status" label="提交状态" width="120" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span v-if="scope.row.status=='1'" style="margin-left: 5px;color: #007df8">已保存</span>
          <span v-if="scope.row.status=='2'" style="margin-left: 5px;color: #13ce66">已审核</span>
          <span v-if="scope.row.status=='-99'" style="margin-left: 5px;color: red">审核不通过</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="130" align="center">
        <template slot-scope="scope">
          <el-button circle icon="el-icon-edit-outline" type="primary" title="编辑" size="small"
            @click="rowEdit(scope.$index, scope.row)"></el-button>
          <el-button circle icon="el-icon-delete" type="danger" title="删除" size="small"
            @click="rowDel(scope.$index, scope.row, $event);"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页-->
    <el-pagination
      :page-sizes="[10, 20, 30, 40]"
      :page-size="10"
      :total="100"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!--编辑-弹出层-->
    <el-dialog
      title="新增"
      :visible.sync="isShowEditDialog"
      width="1000px"
      @close="dialogClose">
      <el-form
        ref="editForm"
        :model="formFileds"
        label-width="55px"
        :rules="rules">
        <el-row>
            <el-col :span="12">
              <el-form-item label="患者姓名" label-width="120px">
<!--                <el-date-picker v-model="formFileds.col1" value-format="yyyy-MM-dd" :editable="false" :clearable="false"></el-date-picker>-->
                <el-input v-model="formFileds.col1" style="width: 300px"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="住院号" label-width="120px">
<!--                <el-date-picker v-model="formFileds.col2" value-format="yyyy-MM-dd" :editable="false" :clearable="false"></el-date-picker>-->
                <el-input v-model="formFileds.col2" style="width: 300px"></el-input>
              </el-form-item>
            </el-col>
        </el-row>
        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="年龄" prop="name" label-width="120px">
<!--              <el-checkbox-group v-model="formFileds.col3">-->
<!--                <el-checkbox label="就诊卡号"></el-checkbox>-->
<!--                <el-checkbox label="处方号"></el-checkbox>-->
<!--                <el-checkbox label="健康号"></el-checkbox>-->
<!--              </el-checkbox-group>-->
              <el-input v-model="formFileds.col3" style="width: 300px"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别" prop="name" label-width="120px">
              <el-select v-model="formFileds.col4" placeholder="请选择">
                <el-option
                  label="男"
                  value="1">
                </el-option>
                <el-option
                  label="女"
                  value="2">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-form-item label="既往病史" prop="address" label-width="120px">
            <el-input type="textarea" v-model="formFileds.col5"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="预期治疗疾病或作用" prop="address" label-width="120px">
            <el-input type="textarea" v-model="formFileds.col6"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="事件发生日期" prop="address" label-width="120px">
<!--            <el-input type="textarea" v-model="formFileds.col7"></el-input>-->
            <el-date-picker v-model="formFileds.col7" value-format="yyyy-MM-dd" :editable="false" :clearable="false"></el-date-picker>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="事件发生或知悉日期" prop="address" label-width="120px">
            <el-date-picker v-model="formFileds.col8" value-format="yyyy-MM-dd" :editable="false" :clearable="false"></el-date-picker>
<!--            <el-input type="textarea" v-model="formFileds.col8"></el-input>-->
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="伤害表现" prop="address" label-width="120px">
            <el-input type="textarea" v-model="formFileds.col9"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="器械故障表现" prop="address" label-width="120px">
            <el-input type="textarea" v-model="formFileds.col10"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="医疗器械实际使用场所" prop="address" label-width="120px">
            <el-select v-model="formFileds.col11" placeholder="请选择">
              <el-option
                label="医院"
                value="1">
              </el-option>
              <el-option
                label="院外"
                value="2">
              </el-option>
            </el-select>
<!--            <el-input type="textarea" v-model="formFileds.col11"></el-input>-->
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="事件后果" prop="address" label-width="120px">
<!--            <el-input type="textarea" v-model="formFileds.col12"></el-input>-->
            <el-select v-model="formFileds.col12" placeholder="请选择">
              <el-option
                label="危机生命"
                value="1">
              </el-option>
              <el-option
                label="严重损伤"
                value="2">
              </el-option>
            </el-select>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="死亡日期" prop="address" label-width="120px">
            <el-date-picker v-model="formFileds.col13" value-format="yyyy-MM-dd" :editable="false" :clearable="false"></el-date-picker>
<!--            <el-input type="textarea" v-model="formFileds.col13"></el-input>-->
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="事件陈述" prop="address" label-width="120px">
            <el-input type="textarea" v-model="formFileds.col14"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="事件报告状态" prop="address" label-width="120px">
            <el-select v-model="formFileds.col15" placeholder="请选择">
              <el-option
                label="已通知医院"
                value="1">
              </el-option>
              <el-option
                label="还未通知"
                value="2">
              </el-option>
            </el-select>
<!--            <el-input type="textarea" v-model="formFileds.col15"></el-input>-->
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="医疗器械分类名称" prop="address" label-width="120px">
            <el-input type="textarea" v-model="formFileds.col16"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="产品名称" prop="address" label-width="120px">
            <el-input type="textarea" v-model="formFileds.col17"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="注册证号/曾用注册证号" prop="address" label-width="120px">
            <el-input type="textarea" v-model="formFileds.col18"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="生成企业名称" prop="address" label-width="120px">
            <el-input type="textarea" v-model="formFileds.col19"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="生成企业地址" prop="address" label-width="120px">
            <el-input type="textarea" v-model="formFileds.col20"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="生成企业电话" prop="address" label-width="120px">
            <el-input type="textarea" v-model="formFileds.col21"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="型号规格" prop="address" label-width="120px">
            <el-input type="textarea" v-model="formFileds.col22"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="产品批号" prop="address" label-width="120px">
            <el-input type="textarea" v-model="formFileds.col23"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="生成批号" prop="address" label-width="120px">
            <el-input type="textarea" v-model="formFileds.col24"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="UDI" prop="address" label-width="120px">
            <el-input type="textarea" v-model="formFileds.col25"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="生产日期" prop="address" label-width="120px">
            <el-date-picker v-model="formFileds.col26" value-format="yyyy-MM-dd" :editable="false" :clearable="false"></el-date-picker>
<!--            <el-input type="textarea" v-model="formFileds.col26"></el-input>-->
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="有效期至" prop="address" label-width="120px">
            <el-date-picker v-model="formFileds.col27" value-format="yyyy-MM-dd" :editable="false" :clearable="false"></el-date-picker>
<!--            <el-input type="textarea" v-model="formFileds.col27"></el-input>-->
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="停用日期" prop="address" label-width="120px">
            <el-date-picker v-model="formFileds.col28" value-format="yyyy-MM-dd" :editable="false" :clearable="false"></el-date-picker>
<!--            <el-input type="textarea" v-model="formFileds.col28"></el-input>-->
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="植入日期" prop="address" label-width="120px">
            <el-date-picker v-model="formFileds.col29" value-format="yyyy-MM-dd" :editable="false" :clearable="false"></el-date-picker>
<!--            <el-input type="textarea" v-model="formFileds.col29"></el-input>-->
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="操作人" prop="address" label-width="120px">
            <el-select v-model="formFileds.col30" placeholder="请选择">
              <el-option
                label="专业人员"
                value="1">
              </el-option>
              <el-option
                label="医生"
                value="2">
              </el-option>
            </el-select>
<!--            <el-input type="textarea" v-model="formFileds.col30"></el-input>-->
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="事件发生原因分析" prop="address" label-width="120px">
            <el-select v-model="formFileds.col31" placeholder="请选择">
              <el-option
                label="产品原因包括说明书"
                value="1">
              </el-option>
              <el-option
                label="医生"
                value="2">
              </el-option>
            </el-select>
<!--            <el-input type="textarea" v-model="formFileds.col31"></el-input>-->
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="事件原因分析描述" prop="address" label-width="120px">
            <el-input type="textarea" v-model="formFileds.col32"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="初步处置情况" prop="address" label-width="120px">
            <el-input type="textarea" v-model="formFileds.col33"></el-input>
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="报告人" prop="address" label-width="120px">
            <el-select v-model="formFileds.col31" placeholder="请选择">
              <el-option
                label="医生"
                value="1">
              </el-option>
              <el-option
                label="技师"
                value="2">
              </el-option>
            </el-select>
<!--            <el-input type="textarea" v-model="formFileds.col34"></el-input>-->
          </el-form-item>
        </el-row>
        <el-row>
          <el-form-item label="事件报告日期" prop="address" label-width="120px">
            <el-date-picker v-model="formFileds.col35" value-format="yyyy-MM-dd" :editable="false" :clearable="false"></el-date-picker>
<!--            <el-input type="textarea" v-model="formFileds.col35"></el-input>-->
          </el-form-item>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="科室" label-width="120px">
              <el-input type="textarea" v-model="formFileds.col36"></el-input>
<!--              <el-date-picker v-model="formFileds.col36" value-format="yyyy-MM-dd" :editable="false" :clearable="false"></el-date-picker>-->
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报告人" label-width="120px">
              <el-input type="textarea" v-model="formFileds.col37"></el-input>
<!--              <el-date-picker v-model="formFileds.col37" value-format="yyyy-MM-dd" :editable="false" :clearable="false"></el-date-picker>-->
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item>
          <el-button type="primary" @click="handleSubmit(formFileds.id)" class="pull-right margin-l-25">确定</el-button>
          <el-button @click="isShowEditDialog = false;" class="pull-right">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: "Table",
    data() {
      return {
        checkList:[],
        formFileds: {
          date: '',
          name: '',
          address: '',
          id: '',
          col1:undefined,
          col2:undefined,
          col3:undefined,
          col4:undefined,
          col5:undefined,
          col6:undefined,
          col7:undefined,
          col8:undefined,
          col9:undefined,
          col10:undefined,
          col11:undefined,
          col12:undefined,
          col13:undefined,
          col14:undefined,
          col15:undefined,
          col16:undefined,
          col17:undefined,
          col18:undefined,
          col19:undefined,
          col20:undefined,
          col21:undefined,
          col22:undefined,
          col23:undefined,
          col24:undefined,
          col25:undefined,
          col26:undefined,
          col27:undefined,
          col28:undefined,
          col29:undefined,
          col30:undefined,
          col31:undefined,
          col32:undefined,
          col33:undefined,
          col34:undefined,
          col35:undefined,
          col36:undefined,
          col37:undefined,
          status:'1'
        },
        rules: {
          // name: [
          //   {required: true, message: '姓名不能为空', trigger: 'blur, change'}
          // ],
          // address: [
          //   {required: true, message: '地址不能为空', trigger: 'blur, change'}
          // ]
        },
        tableData: [{
          id: 1,
          col11:'器械实际使用场所',
          col14:'事件陈述',
          col10:'器械故障',
          col35: '2016-05-02',
          col37: '张三',
          col1: '张三',
          status:'1'
        }, {
          id: 2,
          col11:'器械实际使用场所',
          col14:'事件陈述',
          col10:'器械故障',
          col35: '2016-05-02',
          col37: '李四',
          col1: '李四',
          status:'1'
        }, {
          id: 3,
          col11:'器械实际使用场所',
          col14:'事件陈述',
          col10:'器械故障',
          col35: '2016-05-02',
          col37: '王五',
          col1: '王五',
          status:'1'
        }, {
          id: 4,
          col11:'器械实际使用场所',
          col14:'事件陈述',
          col10:'器械故障',
          col35: '2016-05-02',
          col37: '赵六',
          col1: '赵六',
          status:'1'
        }],
        isShowEditDialog: false
      }
    },
    methods: {
      handleRowClick(row, event, column) {
        // 仅选中当前行
        this.setCurRowChecked(row);
      },
      handleCheckedAllAndCheckedNone(selection) {
        // 当前选中仅一行时操作-（当前表格行高亮）
        1 != selection.length && this.$refs.list.setCurrentRow();
      },
      dialogClose() {
        // 清空编辑表单
        this.$refs.editForm.resetFields();
      },
      //清空表单信息
      resetForm(){
        this.formFileds={
            date: '',
            name: '',
            address: '',
            id: '',
            col1:undefined,
            col2:undefined,
            col3:undefined,
            col4:undefined,
            col5:undefined,
            col6:undefined,
            col7:undefined,
            col8:undefined,
            col9:undefined,
            col10:undefined,
            col11:undefined,
            col12:undefined,
            col13:undefined,
            col14:undefined,
            col15:undefined,
            col16:undefined,
            col17:undefined,
            col18:undefined,
            col19:undefined,
            col20:undefined,
            col21:undefined,
            col22:undefined,
            col23:undefined,
            col24:undefined,
            col25:undefined,
            col26:undefined,
            col27:undefined,
            col28:undefined,
            col29:undefined,
            col30:undefined,
            col31:undefined,
            col32:undefined,
            col33:undefined,
            col34:undefined,
            col35:undefined,
            col36:undefined,
            col37:undefined,
        }
      },
      rowNew(){
        this.resetForm();
        this.isShowEditDialog = true;
      },
      rowEdit(index, row) {
        this.setCurRowChecked(row);
        // 给编辑弹出层赋值
        // ***这里需要注意的是：因为加了排序 所以tableData的顺序和实际显示的行顺序不一样
        for (let key in this.formFileds) {
          this.formFileds[key] = row[key];
        }
        this.isShowEditDialog = true;
      },
      handleSubmit(){
        if(this.formFileds.id!=null&&this.formFileds.id!=""){
          this.handleEdit(this.formFileds.id);
        }else{
          this.formFileds.id = new Date().getTime();
          this.tableData.push(this.formFileds);
          this.resetForm();
          this.isShowEditDialog = false;
        }
      },
      handleEdit(id) {
        let that = this;
        this.$refs.editForm.validate(isValid => {
          if (!isValid) return;
          // 保存编辑后的数据
          this.tableData.forEach(function(val,index){
            if(val.id == id){
              Object.assign(that.tableData[index], that.formFileds);
            }
          })
          this.isShowEditDialog = false;
          // 考虑到可能编辑了日期-需要重新排序
          // ***注意：手动排序传参和表格的default-sort属性格式不太一样
          this.$refs.list.sort('date', 'descending');
          this.$message.success('编辑成功');
        });
      },
      rowDel(index, row, event) {
        // 让当前删除按钮失焦
        event.target.blur();
        this.$confirm('确定要删除当前行吗？', '删除', {
          comfirmButtonText: '确定',
          cancelButtonText: '取消'
        }).then(() => {
          this.tableData.splice(row.id, 1);
          this.$message.success('删除成功');
          return false;
        });
      },
      // 选中当前行-当前行的复选框被勾选
      setCurRowChecked(row) {
        this.$refs.list.clearSelection();
        this.$refs.list.toggleRowSelection(row);
      }
    }
  }
</script>

<style scoped lang="less">
.el-form {
  padding: 0 10px;
}
.el-date-editor {
  width: 100% !important;
}
</style>
